define(['require' , 'exports' , 'module' , 'jquery' , 'layer' , 'common/common' , 'baiduTemplate' , 'dropload'] , function (require , exports , module , $ , layer , common) {

    var dropload = function() {
        // 上拉加载-----start------
        dropload = $('#content').dropload({
            distance : 100,
            domDown : {
                domClass   : 'dropload-down',
                domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
                domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
                domNoData  : '<div class="dropload-noData">暂无数据</div>'
            },
            loadDownFn : function(load){
                var page = window.sessionStorage.getItem('orderpage');
                if(page == undefined || page == null || page == 'NaN'){
                    page = 1;
                }

                var type = $('#type').val();

                $.ajax({
                    type: 'GET',
                    url: '/order/list?page=' + page + '&type=' + type ,
                    dataType: 'json',
                    success: function(data){
                        if(data.code == 0) {
                            if (data.data.list.length == 0) {
                                load.noData(true);
                                load.resetload();
                            }else {
                                window.sessionStorage.setItem('orderpage' , data.data.pageData.page * 1 + 1);
                                var html = baidu.template('orderList', {order: data.data.list});
                                $('#list').append(html);
                                load.resetload();
                            }
                        }else{
                            load.noData(true);
                            load.resetload();
                        }
                    },
                    error: function(xhr, type){
                        layer.open({
                            content : '服务器链接错误' ,
                            skin : 'msg' ,
                            time : 2
                        });
                        // 即使加载出错，也得重置
                        load.noData(true);
                        load.resetload();
                    }
                });

            }
        });
        return dropload;
    };
    exports.dropload = dropload;
});
